package cglib;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;

public class CGlibClassFactory {

	private static CGlibClassFactory factory = new CGlibClassFactory();
	
	public static CGlibClassFactory getInstance(){
		return CGlibClassFactory.factory;
	}
	
	public Object createProxyUsingNoOp(Class targerClass){
		Enhancer enhancer = new Enhancer();
	    enhancer.setSuperclass(targerClass);
	    enhancer.setCallback(NoOp.INSTANCE);
	    return enhancer.create();
	}
	
	
	public Object createProxyUsingMethodInterceptor(Class targerClass){
		Enhancer enhancer = new Enhancer();
	    enhancer.setSuperclass(targerClass);
	    enhancer.setCallback(new MyInterceptor());
	    return enhancer.create();
	}
	
	public Object createProxyUsingFilter(Class targerClass){
		Enhancer enhancer = new Enhancer();
	    enhancer.setSuperclass(targerClass);
	    enhancer.setCallbackFilter(new MyCallbackFilter());
	    enhancer.setCallbacks(new Callback[]{new MyInterceptor(),NoOp.INSTANCE});
		return enhancer.create();
	}
	
	public Object createProxyUsingFixedValue(Class targerClass){
		Enhancer enhancer = new Enhancer();
	    enhancer.setSuperclass(targerClass);
	    enhancer.setCallback(new MyFixedValue());
	    return enhancer.create();
	}
	
	public Object createProxyUsingLasyLoader(Class targerClass){
	    return Enhancer.create(targerClass,new MyLazyLoader());
	}
}
